import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yinsh
 * Date: 2025-02-20
 * Time: 15:23
 */
public class Test {
    public void mergeSort(int[] array) {
        int left = 0;
        int right = array.length-1;
        partition(array,left,right);

    }
    private static void partition (int[] array,int left,int right) {
        int mid = (left+right)/2;
        if (left >= right) {
            return;
        }
        partition(array,left,mid);
        partition(array,mid+1,right);
        merge(array,left,right,mid);
    }
    private static void merge(int[] array,int left,int right,int mid) {
        int i = mid + 1;
        int start = left;
        int[] tampArr = new int[right-left+1];
        int index = 0;
        while (left <= mid && i <= right) {
            if (array[left] >= array[i]) {
                tampArr[index] = array[i];
                index++;
                i++;
            }else {
                tampArr[index] = array[left];
                index++;
                left++;
            }
        }
        while (left <= mid) {
            tampArr[index] = array[left];
            index++;
            left++;
        }
        while (i <= right) {
            tampArr[index] = array[i];
            index++;
            i++;
        }
        for (int j = 0; j < tampArr.length; j++) {
            array[start+j] = tampArr[j];
        }
    }
}
